/**
 * @file		adc.h
 * @brief		A/D Convertor
 * @note		None
 * @attention	None
 * 
 * <B><I>ALL RIGHTS RESERVED, COPYRIGHT&copy; SOCIONEXT INCORPORATED 2016</I></B>
 */

/** @weakgroup adc_overview
@{
	A/D Convertor base function.<br>
	<br>
	Control parameter setting<br>
	- Channel number : Ch0 - Ch7<br>
	- Conversion mode : Single conversion<br>
	- Start trigger selection : Trigger by timer<br>
	- Timer trigger selection : 32 bit reload timer<br>
	- Start by Timer trigger :  Timer toggle output<br>
	- External trigger edge selection : Rise edge<br>
	- Sampling time : 0xFF<br>
	- Auto power down control : Enable<br>
	- AD comparison data : 0x03FF<br>
@}*//* --- end of adc_overview */

/** @weakgroup adc_sequence
@{
	- @ref adc_sequence
	- @ref adc_sample
	
	@section adc_sequence Sequence example of ADC.
	@image html adc.png
	<br>

	<hr>
	@section adc_sample Sample code
	The example of ADC is as follows.

	@code
	void ADC_Sample()
	{
		int ret;
		T_ADC_BUFFER buff;
		
		// set Buffer.
		buff.address	= 0xXXXXXXXX;
		buff.size		= 10;
		buff.pointer	= 0xXXXXXXXX;
		buff.overlap	= 0;
		ret = iAdcSetBuffer(&buff);
		if (ret != 0) {
			return;
		}
		
		// set notification : enable.
		ret = iAdcNotification(1);
		if (ret != 0) {
			return;
		}
		
		// start.
		ret = iAdcStart();
		if (ret != 0) {
			iAdcStop();
			return;
		}
	}
	@endcode

@}*//* --- end of adc_sequence */

#ifndef _ADC_H_
#define _ADC_H_

/** @weakgroup adc_definition
@{*/

/** Buffer data */
typedef struct {
	unsigned long		address;		/**< start address of buffer.					*/
	unsigned long		size;			/**< byte size. 0:no-buffer.					*/
	unsigned long		pointer;		/**< address of write pointer.					*/
	int					overlap;		/**< 0:no-overlap, 1:cyclic, 2:same position	*/
} T_ADC_BUFFER;

/* @} */	// adc_definition group

/** @weakgroup adc_func
@{*/

/**
A/D Convertor start.
@retval  0 : success
@retval -1 : failure
*/
extern int iAdcStart(void);

/**
A/D Convertor stop.
@retval  0 : success
@retval -1 : failure
*/
extern int iAdcStop(void);

/**
A/D Convertor notification.
@param [in]	enable		notification enable.<br>
						0:disable, 1:enable
@retval  0 : success
@retval -1 : failure
*/
extern int iAdcNotification(int enable);

/**
set A/D Convertor input buffer.
@param [in]	buff		Buffer data.
@retval  0 : success
@retval -1 : failure
*/
extern int iAdcSetBuffer(T_ADC_BUFFER const* const buff);

/* @} */	// adc_func group

#endif	// _ADC_H_

